package com.lemon.smartsafety.ui.activity.user;

import android.os.CountDownTimer;
import android.support.design.widget.AppBarLayout;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;

import com.lemon.android.http.LemonRequestParams;
import com.lemon.smartsafety.R;
import com.lemon.smartsafety.http.HttpBack;
import com.lemon.smartsafety.http.HttpOkBase;
import com.lemon.smartsafety.http.HttpPath;
import com.lemon.smartsafety.result.BaseMode;
import com.lemon.smartsafetynew.ui.activity.base.NewBaseActivity;
import com.lemon.smartsafety.utils.CommonUtil;
import com.lemon.smartsafety.utils.JsonUtils;
import com.lemon.smartsafety.utils.SystemUtil;
import com.lemon.smartsafety.utils.app.ToastUtil;
import com.rengwuxian.materialedittext.MaterialEditText;

import butterknife.Bind;
import butterknife.OnClick;

public class ResetPassWordActivity extends NewBaseActivity {


    @Bind(R.id.main_title)
    TextView mainTitle;
    @Bind(R.id.toolbar)
    Toolbar toolbar;
    @Bind(R.id.app_bar_layout)
    AppBarLayout appBarLayout;
    @Bind(R.id.metRemarkPhone)
    MaterialEditText metRemarkPhone;
    @Bind(R.id.txt_verCode)
    TextView txtVerCode;
    @Bind(R.id.metRemarkVerCode)
    MaterialEditText metRemarkVerCode;
    @Bind(R.id.metRemarkPassWord)
    MaterialEditText metRemarkPassWord;
    @Bind(R.id.txt_ok)
    TextView txtOk;


    private int verCode=0;

    @Override
    protected void getBundleArgs() {

    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_reset_pass_word;
    }

    @Override
    protected void initTitleView() {
      setTitle("重置密码");
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initHttp() {

    }

    @Override
    protected void initList() {

    }

    @Override
    protected void loadList() {

    }

    @Override
    protected void refreshView() {

    }


    @OnClick({R.id.txt_verCode,R.id.txt_ok})
    public void onSubmitClick(View view) {
        switch (view.getId() ){
            case R.id.txt_verCode:
                if(verCode<=0){
                    starVarCode();
                }
                break;
            case R.id.txt_ok:
                break;
        }

    }


    @Override
    protected void callFinish() {
        mActivity.finish();
    }


    /**
     *  启动读秒倒计时
     */
    private void starVarCode(){
        SystemUtil.HideKeyboard(mActivity);
        verCode=60;

        new CountDownTimer(60000, 1000) {

            public void onTick(long millisUntilFinished) {

                verCode--;
                txtVerCode.setText( verCode +"s");
            }

            public void onFinish() {
                txtVerCode.setText("重新获取");
            }

        }.start();


    }


    /**
     *  重置密码
     */
    private void httpResetPassWord() {

        LemonRequestParams params = new LemonRequestParams("application_user_bind", "bind_id", "");
        params.put("email", metRemarkPassWord.getText().toString().trim());

        showLoading("");
        HttpOkBase.httpBasePost(params, HttpPath.getmBase(HttpPath.Get_score), "", new HttpOkBase.HttpInterface() {
            @Override
            public void callBackFunction(boolean httpClient, String result) {

                dismissLoading();
                if (httpClient) {
                    BaseMode baseMode = JsonUtils.fromJson(result, BaseMode.class);
                    if (!CommonUtil.objIsEmpty(baseMode)) {
                        if (HttpBack.httpBackError(baseMode)) {
                            //mSharedPreferencesHelper.setEmail(metRemarkEmail.getText().toString().trim());
                            finish();
                        } else {
                            ToastUtil.show(baseMode.getMsg());
                        }
                    }
                }
            }
        });

    }





}
